package com.yueyang.sojourn.server.validation.annotation;

import com.yueyang.sojourn.server.validation.DateFormatValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author yemingxing
 * @summary
 * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
 * @since 2020-02-18
 */
@Documented
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(DateFormat.List.class)
@Constraint(validatedBy = {DateFormatValidator.class})
public @interface DateFormat {

    String message() default "日期格式错误";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * format
     *
     * @return String
     */
    String format() default "yyyy-MM-dd";

    /**
     * future date
     *
     * @return boolean
     */
    boolean isFuture() default false;

    /**
     * 字段中文名
     */
    String fieldCN() default "";

    /**
     * Defines several {@link DateFormat} annotations on the same element.
     *
     * @see DateFormat
     */
    @Documented
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @interface List {
        DateFormat[] value();
    }
}
